var OrderSearchModel = function () {
  BaseModel.call(this);
  var self = this;

  var fn = {
    initData: function () {
      self.timeType = 1;
      self.startDate = null;
      self.endDate = null;
      self.deptId = '';
      self.workShop = '';
      self.type = '';
      self.customerId = '';
      self.customer = '';
      self.companyOrderId = '';
      self.factoryId = '';
      self.orderType = '';
      self.isSetOrder = -3;
      self.dutyStatus = '';
      self.materialType = '';
      self.color = '';
      self.coloDescription = '';
      self.model = '';
      self.arts = '';
      self.workShopList = [];
    }
  };

  this.checkValidate = function () {
    var type = this.type;
    if (type !== '') {
      var workShop = this.workShop;
      if (workShop === '') {
        return '请选择车间';
      }
    }
    return '';
  };

  this.getObject = function (pagination) {
    var postData = {
      type: this.type === '' ? 0 : this.type,
      dutyStatus: this.dutyStatus === '' ? 0 : this.dutyStatus
    };

    var fields = ['timeType', 'deptId', 'workShop', 'customerId', 'customer', 'companyOrderId', 'factoryId',
      'color', 'coloDescription', 'model', 'arts'
    ];
    this.setPostData(postData, fields, true, true);

    var otherFields = ['orderType', 'materialType'];
    this.setPostData(postData, otherFields);

    var startDate = this.startDate;
    if (startDate !== null) {
      postData.startDate = moment(startDate).format('YYYY-MM-DD');
    }

    var endDate = this.endDate;
    if (endDate !== null) {
      postData.date = moment(endDate).format('YYYY-MM-DD');
    }

    var isSetOrder = this.isSetOrder;
    if (isSetOrder !== '') {
      postData.isSetOrder = isSetOrder;
    }

    if (pagination !== undefined) {
      var currentPage = pagination.currentPage;
      var pageSize = pagination.pageSize;
      var start = (currentPage - 1) * pageSize;
      postData.start = start;
      postData.length = pageSize;
    }

    return postData;
  };

  fn.initData();
};
